<?php
if (isset($HTTP_GET_VARS['active'])&&(isset($HTTP_GET_VARS['n'])))
{
	$keyactive= $HTTP_GET_VARS["active"];	
	$number= $HTTP_GET_VARS["n"];	
   	if($number=="hienthi")	$result_hieuluc = mysql_query("UPDATE tintuc SET ghichu='khonghienthi' WHERE id_tintuc='$keyactive'");
	if($number=="khonghienthi")	$result_hieuluc = mysql_query("UPDATE tintuc SET ghichu='hienthi' WHERE id_tintuc='$keyactive'"); 			
	 if ($result_hieuluc) echo "<script>window.location='?m=tintuc';</script>";  
}
if(isset($_POST["act"]))
{
	if(isset($_POST["xoa"]))
	{
		$chon=$_POST["chon"];
		$count=count($chon);
		if($count==0)
			echo "<script>alert('Chưa chọn nội dung cần xóa');</script>";
		else{
			for ($j=0;$j<$count;$j++)
			{	
				$SQL_xoa = "DELETE FROM tintuc WHERE id_tintuc='$chon[$j]'";
			//	echo "$SQL_xoagiohang";
				$kq_xoa=mysql_query($SQL_xoa);
				$n+=mysql_affected_rows();
			}					
			echo "<script>alert('Đã xóa $n nội dung');</script>";				

		}		
	
	}
}
?>
<form method="post" name="form" id="form">
<table width="960" height="70" border="0" cellspacing="0" cellpadding="0" bgcolor="#fbfbfb" bordercolordark="#FFFFFF">
	  <tr>
      	<td style="border-top:1px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; border-left:1px solid #CCCCCC"><div align="left" style="color:#0B55C4; font-family:Tahoma; font-size: 16px; font-weight:bold; padding-left:20px">QUẢN LÝ TIN TỨC - KHUYẾN MÃI
      	</div></td>
      	<td style="border-top:1px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; height:65px; width:55px">
		<input type="button" value='' onClick="document.form.action='../admincp/?m=tintuc-insert'; document.form.submit();" style="background:url(../images/bt_them.jpg); width:55px; height:65px;">
		</td>		
		<td style="border-top:1px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; border-right:1px solid #CCCCCC; height:65px; width:55px">
		<input type="submit" name="xoa" value='' onClick="return checktintuc();document.form.submit();" style="background:url(../images/bt_xoa.jpg); width:55px; height:65px;">       
        </td>
      </tr>
    </table>
<table width="960" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td colspan="6" class="tieude" align="center">CÁC TIN ĐANG CÓ</td>
  </tr>
  <tr height="30" bgcolor="#b3d5f9">
    <td align="center" width="100" style="border-left:1px solid #333;border-right:1px solid #333">Chọn</td>
    <td width="510" align="center" style="border-right:1px solid #333"><strong>Nội dung</strong><strong></strong></td>
    <td width="150" align="center" style="border-right:1px solid #333"><strong>Hiển thị</strong></td>
    <td width="100" align="center" style="border-right:1px solid #333">Sửa</td>
    <td align="center" width="100" style="border-right:1px solid #333">Xóa</td>
    
  </tr>  
<?php
        $kq=mysql_query("select count(*) from tintuc"); 
        $r=mysql_fetch_array($kq);
        $numrow=$r[0];		
        //số record cho 1 trang
        $pagesize=10;
        //Tính tổng số trang
        $pagecount=ceil($numrow/$pagesize);			
        //Xác định số trang cho mỗi lần hiển thị
        $segsize=5;
        //Thiết lập trang hiện hành
        if(!isset($_GET["page"]))
			 $curpage=1;
        else	
        	 $curpage=$_GET["page"];
        if($curpage<1)
			 $curpage=1;
        if($curpage>$pagecount) $curpage=$pagecount;
        //Xác định số phân đoạn của trang
        $numseg=($pagecount % $segsize==0)?($pagecount/$segsize):(int)($pagecount/$segsize+1);
        //Xác định phân đoạn hiện hành của trang
        $curseg=($curpage % $segsize==0)?($curpage/$segsize):(int)($curpage/$segsize+1);   
		$k=($curpage-1)*$pagesize;
		
	//******************************** Nội Dung *********************************//
		$sql3="select * from tintuc order by id_tintuc ASC limit $k,$pagesize";
		$kq3=mysql_query($sql3);
		if(!$kq3)
			echo "";
		else{
		while($r3=mysql_fetch_array($kq3))
		{
			$id_tintuc=$r3["id_tintuc"];
			$noidung=$r3["noidung"];
			$ghichu=$r3["ghichu"];
  ?>
  <tr>
  <td width="100" align="center" style="border-left:1px solid #333;border-bottom:1px solid #333; border-right:1px solid #333" valign="top">
  <input type="checkbox" name="chon[]" value="<?php echo $id_tintuc; ?>"/></td>  
    <td width="510" height="30" align="left" style="border-bottom:1px solid #333; border-right:1px solid #333"><div style="padding-left:5px; padding-right:5px"><?php echo "$noidung"; ?></div></td>
    <td width="150" align="center" style="border-bottom:1px solid #333; border-right:1px solid #333; padding-left:5px; padding-right:5px" valign="center">
    <?php echo "<a href='?m=tintuc&active=$id_tintuc&n=$ghichu'>";
		if($ghichu=="khonghienthi")
			echo "<img src='img/khonghieuluc.gif' border='0'>"; 
		else 
			echo "<img src='img/hieuluc.gif' border='0'>";
		echo "</a>";
		?>
      </td>
    <td width="100" align="center" style="border-bottom:1px solid #333; border-right:1px solid #333; padding-left:5px; padding-right:5px" valign="top"><a href="?m=tintuc-update&amp;id_tintuc=<?php echo "$id_tintuc"; ?>">Sửa</a></td>
    <td width="100" align="center" style="border-bottom:1px solid #333; border-right:1px solid #333" valign="top"><a href="?m=tintuc-del&idtintuc=<?php echo "$id_tintuc"; ?>" onclick="return checktintuc()">Xóa</a></td>   
  </tr>
 <?php
		}
		}
 ?>
  <tr>
	<td colspan="6" class="ketthuc">
 <?php
    if($numrow==0)
		echo "Hiện tại chưa có nội dung nào!!";
	else{  
    if($curseg>1)
        echo "<a href='?m=tintuc&page=".(($curseg-1)*$segsize)."'><b>Previous</b></a> &nbsp;";
        $n=$curseg*$segsize<=$pagecount?$curseg*$segsize:$pagecount;
        for($i=($curseg-1)*$segsize+1;$i<=$n;$i++)
		{
			if($curpage==$i)
				echo "<a href='?m=tintuc&page=".$i."'><font color='#FF0000'>[".$i."]</font></a> &nbsp;";
			else
				echo "<a href='?m=tintuc&page=".$i."'><font color='#FFF'>[".$i."]</font></a> &nbsp;";
		}
        if($curseg<$numseg)
		echo "<a href='?m=tintuc&page=".(($curseg*$segsize)+1)."'><b>Next</b></a> &nbsp;";		
	}
?>
    </td>
  </tr> 
</table>
  <input type="hidden" name="act">
</form>